<script src="<?php echo base_url()?>js/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url()?>js/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready( function() {
        $(function() {
            $('#loading').ajaxStart(function(){
                $(this).fadeIn();
            }).ajaxStop(function(){
                $(this).fadeOut();
            });
        var w = parseInt($('#week_count3').val());
        for(var a=0;a<=w;a++){
            $('#click_cmb3'+a).click(function(){
//alert(a);
                if ($("#container5").is(":hidden")) {
                    $("#container5").slideDown("slow");
                    //$('#click').text('Tutup');
                } else {
                    $("#container5").slideUp("slow");

                }
            });
        }
        $('#menu3 a').click(function() {
            var url = $(this).attr('href');
            $('#container5').load(url);
            return false;
        });


         var w = parseInt($('#week_count3').val());
        for(var a=0;a<=w;a++){
            $('#click_cmb4'+a).click(function(){
//alert(a);
                if ($("#container6").is(":hidden")) {
                    $("#container6").slideDown("slow");
                    //$('#click').text('Tutup');
                } else {
                    $("#container6").slideUp("slow");

                }
            });
        }
        $('#menu4 a').click(function() {
            var url = $(this).attr('href');
            $('#container6').load(url);
            return false;
        });

         var w = parseInt($('#week_count3').val());
        for(var a=0;a<=w;a++){
            $('#click_cmb5'+a).click(function(){
//alert(a);
                if ($("#container7").is(":hidden")) {
                    $("#container7").slideDown("slow");
                    //$('#click').text('Tutup');
                } else {
                    $("#container7").slideUp("slow");

                }
            });
        }
        $('#menu5 a').click(function() {
            var url = $(this).attr('href');
            $('#container7').load(url);
            return false;
        });

        });

    });
</script>
<?php $this->load->helper('HTML'); 
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
<p>&nbsp;</p>
<h2 class="title">Calon Manager Khusus Tiga Bulan</h2>
<?php
$tduabulan=0;
$total_rekrutb2=0;
$total_jualrekrutb3=0;
$ttigabulan=0;
?>
<form method="post">
    <table width="90%" border="0" cellpadding="1" cellspacing="1" id="data" align="center">
        <thead>
            <?php if(isset($error)) {?>
            <tr>
                <td colspan="5">
                        <?php echo $error?>
                </td>
            </tr>
                <?php }else { ?>
            <tr  align="center" class="table" >
        <input type="hidden" id="week_count3" value="<?php echo count($weeks)?>">
        <th ><?php echo $bulan . " " . $tahun?></th>
            <?php for($i=0;$i<count($weeks);$i++):?>
        <th >Minggu Ke- <?php echo $weeks[$i]->intid_week;?></th>
            <?php endfor;?>
        <th >Total</th>

        </tr>
        </thead>
        <tbody>

            <!-- ============isi ============ -->
            <tr class='data'>
                <td>Penjualan Pribadi</td>
                    <?php
                    $total=0;
                    $total_pv=0;
                    for($i=0;$i<count($week_pribadi);$i++):?>
                <td align="center">
                            <?php
                            if(!empty($week_pribadi[$i][0]->total)) {
                                echo $week_pribadi[$i][0]->total;
                                $total = $total + $week_pribadi[$i][0]->total;
                                
                            }else {
                                echo "0";
                            }
                            ?>
                </td>
                    <?php endfor;?>
                <td align="center">
                        <?php //$total = 0;
                        echo number_format($total)?>
                </td>
            </tr>

            <tr class="data">
                <td>Rekrut Baru Pribadi</td>
                    <?php
                    $total_rekrut=0;
                    for($i=0;$i<count($week_rekrut);$i++):?>
                <td align="center">
                            <?php
                            if(!empty($week_rekrut[$i][0]->total)) {
                                echo $week_rekrut[$i][0]->total;
                                $total_rekrut = $total_rekrut + $week_rekrut[$i][0]->total;
                            }else {
                                echo "0";
                            }
                            ?>
                </td>
                    <?php endfor;?>
                <td align="center">
                        <?php echo $total_rekrut . " Orang"?>
                </td>
            </tr>
            <tr class="data">
                <td>Penjualan Rekrut</td>
                    <?php
                    $total_jualrekrut=0;
                    for($i=0;$i<count($penjualanrekrut);$i++):?>
                <td align="center">
                            <?php
                            //print_r($penjualanrekrut[$i][0]->total);
                            if(!empty($penjualanrekrut[$i])) {
                                $pr = number_format($penjualanrekrut[$i][0]->total);
                                $week = $penjualanrekrut[$i][0]->intid_week;
                                $total_jualrekrut = $total_jualrekrut + $penjualanrekrut[$i][0]->total;
                                ?>
                    <div id="menu3" align="left" style="height: 40px; width: 30px">
                                    <?php  echo anchor ('calon_manager/view_rekrut4/'.$strkode."/". $week, ($pr), array('id' =>"click_cmb3".$i));?>
                    </div>

                                <?php
                            }else {
                                $pr = "0,00";
                                $week = 0;
                                echo $pr;
                            }
                            ?>

                </td>
                    <?php endfor;?>

                <td align="center">
                        <?php echo number_format($total_jualrekrut)?>
                </td>
            </tr>
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks)?>">Total PV</td>
                <td align="center"><?php echo $week_pv->pv+ $week_pv_pribadi->pv?></td>
            </tr>
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks)?>">Penjualan anak/cucu diluar rekrut baru</td>
                <td align="center"><?php 
				if(!empty($penjualan_luar_rekrut3)){
					$diluar = $penjualan_luar_rekrut3[0]->total;
				}else{
					$diluar = 0;
				}
                        echo number_format($diluar);?></td>
            </tr>
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks)?>">Total Pengejaran CM Bulan ke 1</td>
                <td align="center"><?php $tsatubulan = $diluar + ($total + $total_jualrekrut);
                        echo number_format($tsatubulan)?></td>
            </tr>

        </tbody>
            <?php } ?>
    </table>
<div id="container5" style="width:400px; height: 100px; display:none;">
		No Display Data
</div>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <!-- Bulan Ke dua -->
    <table width="90%" border="0" cellpadding="1" cellspacing="1" id="data" align="center">
        <thead>
            <?php if(isset($error2)) {?>
            <tr>
                <td colspan="5">
                        <?php echo $error2?>
                </td>
            </tr>
                <?php }else { ?>
            <tr  align="center" class="table" >
        <input type="hidden" id="week_count" value="<?php echo count($weeks2)?>">
        <th ><?php echo $bulan1 . " " . $tahun?></th>
            <?php for($i=0;$i<count($weeks2);$i++):?>
        <th >Minggu Ke- <?php echo $weeks2[$i]->intid_week;?></th>
            <?php endfor;?>
        <th >Total</th>

        </tr>
        </thead>
        <tbody>

            <!-- ============isi ============ -->
            <tr class='data'>
                <td>Penjualan Pribadi</td>
                    <?php
                    $totalb2=0;
                    $total_pv1=0;
                    for($i=0;$i<count($week_pribadi2);$i++):?>
                <td align="center">
                            <?php
                            if(!empty($week_pribadi2[$i][0]->total)) {
                                echo $week_pribadi2[$i][0]->total;
                                $totalb2 = $totalb2 + $week_pribadi2[$i][0]->total;
                                $total_pv1 = $total_pv1 + $week_pribadi2[$i][0]->pv;
                            }else {
                                echo "0";
                            }
                            ?>
                </td>
                    <?php endfor;?>
                <td align="center">
                        <?php //$total = 0;
                        echo number_format($totalb2)?>
                </td>
            </tr>

            <tr class="data">
                <td>Rekrut Baru Pribadi</td>
                    <?php
                    $total_rekrutb2=0;
                    for($i=0;$i<count($week_rekrut2);$i++):?>
                <td align="center">
                            <?php
                            if(!empty($week_rekrut2[$i][0]->total)) {
                                echo $week_rekrut2[$i][0]->total;
                                $total_rekrutb2 = $total_rekrutb2 + $week_rekrut2[$i][0]->total;
                            }else {
                                echo "0";
                            }
                            ?>
                </td>
                    <?php endfor;?>
                <td align="center">
                        <?php echo $total_rekrutb2 . " Orang"?>
                </td>
            </tr>
            <tr class="data">
                <td>Penjualan Rekrut</td>
                    <?php
                    $total_jualrekrutb2=0;
                    for($i=0;$i<count($penjualanrekrut2);$i++):?>
                <td align="center">
                            <?php
                            //print_r($penjualanrekrut[$i][0]->total);
                            if(!empty($penjualanrekrut2[$i])) {
                                $pr = number_format($penjualanrekrut2[$i][0]->total);
                                $week = $penjualanrekrut2[$i][0]->intid_week;
                                $total_jualrekrutb2 = $total_jualrekrutb2 + $penjualanrekrut2[$i][0]->total;
                                ?>
                    <div id="menu4" style="height: 40px; width: 5px">
                                    <?php  echo anchor ('calon_manager/view_rekrut4/'.$strkode."/". $week, ($pr), array('id' =>"click_cmb4".$i));?>
                    </div>

                                <?php
                            }else {
                                $pr = "0,00";
                                $week = 0;
                                echo $pr;
                            }
                            ?>

                </td>
                    <?php endfor;?>

                <td align="center">
                        <?php echo number_format($total_jualrekrutb2)?>
                        <?php
                        echo number_format($total_jualrekrutb2)?>
                        <?php $tduabulan = ($totalb2 + $total_jualrekrutb2); ?>
                </td>
            </tr>
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks2)?>">Total PV</td>
                <td align="center"><?php echo $week_pv2->pv+ $week_pv_pribadi2->pv?></td>
            </tr>
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks2)?>">Penjualan anak/cucu diluar rekrut baru</td>
                <td align="center"><?php
				if(!empty($penjualan_luar_rekrut3)){
					$diluarb2 = $penjualan_luar_rekrut3[0]->total;
				}else{
					$diluarb2 = 0;
				}
				
                        echo number_format($diluarb2)?></td>
            </tr>
            <tr class="data">
                <td>&nbsp;</td>
                <td align="center" colspan="<?php echo count($weeks2)?>">Total Pengejaran CM Bulan ke 2</td>
                <td align="center"><?php echo number_format($tduabulan)?></td>
            </tr>

        </tbody>
            <?php } ?>
    </table>
</form>
<div id="container6" style="width:400px; height: 100px; display:none;">
		No Display Data
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>

<!-- Bulan Ke Tiga-->
<table width="90%" border="0" cellpadding="1" cellspacing="1" id="data" align="center">
    <thead>
        <?php if(isset($error3)) {?>
        <tr>
            <td colspan="5">
                    <?php echo $error3?>
            </td>
        </tr>
            <?php }else { ?>
        <tr  align="center" class="table" >
    <input type="hidden" id="week_count" value="<?php echo count($weeks3)?>">
    <th ><?php echo $bulan2 . " " . $tahun?></th>
        <?php for($i=0;$i<count($weeks3);$i++):?>
    <th >Minggu Ke- <?php echo $weeks3[$i]->intid_week;?></th>
        <?php endfor;?>
    <th >Total</th>

</tr>
</thead>
<tbody>

    <!-- ============isi ============ -->
    <tr class='data'>
        <td>Penjualan Pribadi</td>
            <?php
            $totalb3=0;
            $total_pv2=0;
            for($i=0;$i<count($week_pribadi3);$i++):?>
        <td align="center">
                    <?php
                    if(!empty($week_pribadi3[$i][0]->total)) {
                        echo $week_pribadi3[$i][0]->total;
                        $totalb3 = $totalb3 + $week_pribadi3[$i][0]->total;
                        $total_pv2 = $total_pv2 + $week_pribadi3[$i][0]->pv;
                    }else {
                        echo "0";
                    }
                    ?>
        </td>
            <?php endfor;?>
        <td align="center">
                <?php //$total = 0;
                echo number_format($totalb3)?>
        </td>
    </tr>

    <tr class="data">
        <td>Rekrut Baru Pribadi</td>
            <?php
            $total_rekrutb3=0;
            for($i=0;$i<count($week_rekrut3);$i++):?>
        <td align="center">
                    <?php
                    if(!empty($week_rekrut3[$i][0]->total)) {
                        echo $week_rekrut3[$i][0]->total;
                        $total_rekrutb3 = $total_rekrutb3 + $week_rekrut3[$i][0]->total;
                    }else {
                        echo "0";
                    }
                    ?>
        </td>
            <?php endfor;?>
        <td align="center">
                <?php echo $total_rekrutb3 . " Orang"?>
        </td>
    </tr>
    <tr class="data">
        <td>Penjualan Rekrut</td>
            <?php
            $total_jualrekrutb3=0;
            for($i=0;$i<count($penjualanrekrut3);$i++):?>
        <td align="center">
                    <?php
                    //print_r($penjualanrekrut[$i][0]->total);
                    if(!empty($penjualanrekrut3[$i])) {
                        $pr = number_format($penjualanrekrut3[$i][0]->total);
                        $week = $penjualanrekrut3[$i][0]->intid_week;
                        $total_jualrekrutb3 = $total_jualrekrutb3 + $penjualanrekrut3[$i][0]->total;
                        ?>
            <div id="menu5" style="height: 40px; width: 5px">
                            <?php  echo anchor ('calon_manager/view_rekrut4/'.$strkode."/". $week, ($pr), array('id' =>"click_cmb5".$i));?>
            </div>

                        <?php
                    }else {
                        $pr = "0,00";
                        $week = 0;
                        echo $pr;
                    }
                    ?>

        </td>
            <?php endfor;?>

        <td align="center">
                <?php echo number_format($total_jualrekrutb3)?>
                <?php
                echo number_format($total_jualrekrutb3)?>
                <?php $ttigabulan = ($totalb2 + $total_jualrekrutb3); ?>
        </td>
    </tr>
    <tr class="data">
        <td>&nbsp;</td>
         
        <td align="center" colspan="<?php echo count($weeks3)?>">Total PV</td>
        <td align="center"><?php echo $week_pv3->pv+ $week_pv_pribadi3->pv?></td>
    </tr>
    <tr class="data">
        <td>&nbsp;</td>
        <td align="center" colspan="<?php echo count($weeks3)?>">Penjualan anak/cucu diluar rekrut baru</td>
        <td align="center"><?php 
		if(!empty($penjualan_luar_rekrut3)){
					$diluarb3 = $penjualan_luar_rekrut3[0]->total;
				}else{
					$diluarb3 = 0;
				}
                echo number_format($diluarb2)?></td>
    </tr>
    <tr class="data">
        <td>&nbsp;</td>
        <td align="center" colspan="<?php echo count($weeks3)?>">Total Pengejaran CM Bulan ke 3</td>
        <td align="center"><?php echo number_format($ttigabulan)?></td>
    </tr>

</tbody>
    <?php } ?>
</table>
<div id="container7" style="width:400px; height: 100px; display:none;">
		No Display Data
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form action="<?php echo $form_action?>" method="post" id="frm">
    <table width="90%" border="0" cellpadding="1" cellspacing="1" id="data" align="center">
        <tr class="data">
            <td align="center" colspan="4">Total Pengejaran CM Selama Tiga Bulan</td>
            <td align="center"><?php
                $totcm3 = $tsatubulan + $tduabulan + $ttigabulan;
                echo number_format($totcm3);
                ?></td>
        </tr>
        <tr class="data">
            <td align="center" colspan="4">Rekrut Pribadi Baru</td>
            <td align="center"><?php
                $trekruttigabulan = $total_rekrutb2 + $total_rekrut + $total_jualrekrutb3;
                echo ($trekruttigabulan). " Orang";

                ?></td>
        </tr>
        <?php
        $totpv = $total_pv + $total_pv1 + $total_pv2;
        if(($trekruttigabulan >= 6)&&($totcm3 >= 12000000)) {
            ?>
        <tr>
            <td colspan="5" align="left">
                <input type="hidden" name="strkode_dealer"  id="strkode_dealer" value="<?php echo $strkode?>">
                <input type="hidden" name="khusus"  id="khusus" value="<?php echo $khusus?>">
                <input type="hidden" name="totcm3"  id="totcm3" value="<?php echo $totcm3?>">
                <input type="hidden" name="total_pv"  id="total_pv" value="<?php echo $totpv?>">

                <input type="submit" name="simpan" id="submit4" value="simpan"></td>
            <td colspan="2" align="center"></td>
        </tr>
            <?php }else { ?>
        <form method="post" action="<?php echo $form_action;?>">
    	<table id="data">
        <tr>
            <td>Tidak Memenuhi Syarat ! Belum bisa Melanjutkan ke Calon Manager Berikutnya</td>
            <td>
                <input type="hidden" name="strkode_dealer"  id="strkode_dealer" value="<?php echo $strkode?>">
                <input type="submit" name="submit" value="Reset Pra Cm"> </td>
        </tr>
    </table>
</form>

            <?php
        }
        ?>
    </table>
</form>
<div id="message4"></div>
<script type="text/javascript">
        $(document).ready( function() {
            $("#rec1").dialog({
                autoOpen: false,
                modal: true,
                width: '300'
            });
            $('#submit4').click(function() {


                var form_data = {
                    strkode_dealer : $('#strkode_dealer').val(),
                    khusus : $('#khusus').val(),
                    total_omset : $('#total_omset').val(),
                    total_pv : $('#total_pv').val(),
                    ajax : '1'
                };
                $.ajax({
                    url: "<?php echo base_url(); ?>calon_manager/last_selection",
                    type: 'POST',
                    async : false,
                    data: form_data,
                    success: function(msg) {
                        $('#message4').html(msg);
                    }
                });
                return false;
            });
        });
</script>